package com.tgy.thread;

import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.TIMEOUT;

import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 2020-08-28 11:51
 */
//@Slf4j(topic = "daemon-thread")
@Slf4j
public class DaemonThread {

    private Thread thread;

    DaemonThread(){

        thread = new Thread(()->{

            while (true){

                System.out.println("111");

                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }, "daemon-thread");

        /**
         *
         * java 里面的守护线程与主线程共死，当主线程挂了之后，守护线程与一起挂，
         *
         * 作用
         *  1. 垃圾回收线程是守护线程
         */

        thread.setDaemon(true);
        thread.start();

    }


    public static void main(String[] args) {

        log.info("11111");
        DaemonThread daemonThread = new DaemonThread();

    }
}
